package com.cyz.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/Login")
public class Login {
	
	/**
	  *  ��֤�û���¼�Ƿ��¼
	 * @throws IOException 
	 */
	@RequestMapping("/validateLogin")
	public void validateLogin(HttpServletRequest request,HttpServletResponse response) throws IOException {
		//request.getSession().setAttribute("userName","1");//test
		PrintWriter printWriter = response.getWriter();
		System.out.println(request.getSession().getAttribute("userName"));
		//System.out.println("1111111111111111111");
		if(null == request.getSession().getAttribute("userName")) { //δ��¼
			printWriter.write("{\"res\":\"0\"}");
		} else {
			printWriter.write("{\"res\":\"1\"}");
		}
		
		
		
		printWriter.close();
	}
	@RequestMapping("/login")
	public void login(HttpServletRequest request,HttpServletResponse response) throws IOException {
		PrintWriter printWriter = response.getWriter();
		
		String userName = request.getParameter("userName");
		request.getSession().setAttribute("userName",userName);//���û�����session
		
		printWriter.close();
	}
}
